import {
  sendMessageCategoryOptions,
  sendMessageRoleTypeOptions,
} from '@/enums/messageLog'
import { validateUID } from '@/utils/id'

export default function useConfig() {
  const filterBarScheme: CloudFilterBarScheme = {
    widgets: [
      {
        widget: 'select',
        field: 'role_type',
        allText: '全部邮件',
        options: [...sendMessageRoleTypeOptions],
      },
      {
        widget: 'select',
        field: 'message_type',
        allText: '全部类型',
        options: [...sendMessageCategoryOptions],
      },
      {
        widget: 'strong-search',
        placeholder: '默认按照邮件标题搜索',
        options: [
          { label: '邮件标题', field: 'title' },
          { label: '邮件内容', field: 'content' },
          { label: '收件人邮箱', field: 'email' },
          {
            label: '用户ID',
            field: 'account_uid',
            validate: validateUID,
            message: '用户ID格式不正确',
          },
        ],
      },
    ],
  }

  const columns = buildColumns([
    {
      title: '邮件分类',
      dataIndex: 'role_type',
      render({ record }) {
        return getOptionLabel(record.role_type, sendMessageRoleTypeOptions)
      },
      width: 120,
    },
    {
      title: '邮件类型',
      dataIndex: 'message_type',
      render({ record }) {
        return getOptionLabel(record.message_type, sendMessageCategoryOptions)
      },
      width: 120,
    },
    { title: '邮件标题', dataIndex: 'title' },
    { title: '邮件内容', dataIndex: 'content_original' },
    { title: '收件人邮箱', dataIndex: 'email', width: 200 },
    {
      title: '发送状态',
      dataIndex: 'send_status_type',
      slotName: 'status',
      width: 80,
    },
    {
      title: '发送时间',
      dataIndex: 'created_at',
      width: 160,
      format: 'date-time',
      sortable: sortableSettings,
    },
    {
      title: '操作',
      slotName: 'actions',
      cellClass: 'actions-cell',
      width: 70,
    },
  ])

  return {
    columns,
    filterBarScheme,
  }
}
